home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Commands / Keyboard Shortcuts.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  38.5 KB  |  1,233 lines

  1. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. // *** add case where no sets defined
  4. var DEBUG_FILE = dw.getConfigurationPath() + '/SHORTCUT_DEBUG.txt';
  5.  
  6. //*************** GLOBALS *****************
  7. var helpDoc = MM.HELP_cmdKeyboardShortcuts;
  8. var ultraDevMenuStr = "ultradev";
  9. var PLATFORM = navigator.platform;
  10. var OPP_PLATFORM = (PLATFORM == "Win32") ? "mac" : "win";  // Opposite platform
  11. var CTRL_STR = (PLATFORM == "Win32") ? "Ctrl" : "Cmd";
  12. var NEWLINE = (PLATFORM != "Win32") ? "\x0D" : "\x0D\x0A";
  13. var FILE_CONFIG_PATH = dw.getConfigurationPath();
  14. var FILE_MENUXML_PATH   = null;
  15. var FILE_CUSTOM_SET = FILE_CONFIG_PATH + "/Menus/Custom Sets";
  16. var FILE_ACTIVE_SET = FILE_CUSTOM_SET + "/active set.txt";
  17. var ARRAY_COMMANDS_TREE = new Array();
  18. var ARRAY_COMMANDS_TREENODES = new Array();
  19. var ARRAY_CUSTOM_SETS;
  20. var ACTIVE_SHORTCUT_LIST = new ShortcutList();   // ShortcutList() class defined in Shortcut.js
  21. var CURRENT_SHORTCUT_LIST = new ShortcutList();
  22. var MENU_DOM = null;
  23. var TREE_CONTROL_WIDTH = 'style="width:345px"';
  24. var TREE_COLUMN_ITEM_WIDTH = 'width="158"';
  25. var TREE_COLUMN_ITEM_WIDTH_MAC = 'width="220"'
  26. var TREE_COLUMN_KEY_WIDTH = 'width="140"';
  27. var SEPARATOR_STR = "-----------------------------------------------";
  28. var ACTIVE_SET_STR;
  29. var YIELD_PATH = "../Shared/MM/Images/yield.gif";
  30. var STOP_PATH = "../Shared/MM/Images/stop.gif";
  31. var ALT_STR = (PLATFORM == "Win32") ? "Alt" : "Opt";
  32. var CONFLICT_ID="";
  33. var CAN_APPLY=true;
  34. var LEFT_LAYER = 'left:235px;';
  35. var RIGHT_LAYER = 'left:321px;';
  36. var TOP_LAYER = 'top:402px;';
  37. var LAST_VALID_COMMAND_MI = "";  //last valid command menu item
  38. var MODIFIER_KEYS = new Array("Ctrl","Cmd","Alt","Opt","Shift");
  39. var SNIPPETS_MODIFIED = false;
  40. // UI Globals
  41. var IBTN_duplicateBtn, IBTN_renameBtn, IBTN_saveAsTextBtn, IBTN_deleteBtn,IBTN_addBtn;
  42. //******************* API **********************
  43.  
  44. function loadGlobals()
  45.   {
  46.   if (FILE_MENUXML_PATH != null &&
  47.     MENU_DOM != null)
  48.     return;
  49.  
  50.   FILE_MENUXML_PATH = dw.getMenuFile();
  51.   FILE_SNIPPETSXML_PATH = dw.getSnippetsFile();
  52.   MENU_DOM = dw.getDocumentDOM(FILE_MENUXML_PATH);
  53.   }
  54.  
  55. function cmdOK()
  56. {
  57.   checkLockedFiles();
  58.   if (document.newShortcutEntry.value && !isSet(MENU_CURRENT_SET.getValue(), "factory"))
  59.     updateUI("applyButton");
  60.   var activeSet = CURRENT_SHORTCUT_LIST.shortcutListName;
  61.   if (!isSet(MENU_CURRENT_SET.getValue(), "factory"))
  62.     CURRENT_SHORTCUT_LIST.writeToShortcutXML(FILE_CUSTOM_SET+"/"+ MENU_CURRENT_SET.getValue(), CURRENT_SHORTCUT_LIST.shortcutListName);
  63.   window.close();
  64.   dreamweaver.runCommand("Processing.htm",CURRENT_SHORTCUT_LIST,FILE_ACTIVE_SET,activeSet,document);
  65.   if(SNIPPETS_MODIFIED)
  66.     dw.snippetPalette.reloadSnippetList();
  67. }
  68.  
  69. function editMenuXML(shortcutList,activeSetPath,activeSet)
  70. {
  71.   writeToMenusXML(shortcutList);
  72.   DWfile.write(activeSetPath, activeSet);
  73.   dreamweaver.reloadMenus();
  74. }
  75.  
  76. function cmdCancel()
  77. {
  78.   window.close();
  79. }
  80.  
  81. function cmdSaveAsText()
  82. {
  83.   var browseURL;
  84.   browseURL = dreamweaver.browseForFileURL("save",LABEL_SaveAsHTML);
  85.   if (browseURL)
  86.   {
  87.   if(browseURL.lastIndexOf(".htm")== -1)
  88.     browseURL +=".htm";
  89.   DWfile.write(browseURL, createHTMLContents());
  90.   }
  91. }
  92.  
  93. //***************** LOCAL FUNCTIONS  ******************
  94.  
  95. function initializeUI()
  96. {
  97.   var  i, commandsArray, menuLabel;
  98.  
  99.   if(checkLockedFiles())
  100.   {
  101.     window.close();
  102.     return;
  103.   }
  104.  
  105.   // Global UI Controls
  106.   MENU_CURRENT_SET = new ListControl("selectCurrentSet");
  107.   MENU_COMMANDS = new ListControl("commandsList");
  108.   LIST_SHORTCUTS = new ListControl("itemList");
  109.   IBTN_duplicateBtn = new ImageButton("duplicateBtn","IBTN_duplicateBtn","sS",false);
  110.   IBTN_renameBtn = new ImageButton("renameBtn","IBTN_renameBtn","sS",false);
  111.   IBTN_saveAsTextBtn = new ImageButton("saveAsTextBtn","IBTN_saveAsTextBtn","sS",false);
  112.   IBTN_deleteBtn = new ImageButton("deleteBtn","IBTN_deleteBtn","sS",false);
  113.   IBTN_addBtn = new ImageButton("addBtn","IBTN_addBtn","sS",false);
  114.   IBTN_minusBtn = new ImageButton("minusBtn","IBTN_minusBtn","sS",false);
  115.   //
  116.   setCurrentSetMenu();
  117.   // select the active set
  118.   MENU_CURRENT_SET.setIndex(getIndexOfItem(MENU_CURRENT_SET.get('all'),ACTIVE_SET_STR));
  119.   LAST_VALID_COMMAND_MI = MENU_CURRENT_SET.getValue();
  120.   if (PLATFORM == "Win32"){
  121.     if (dw.isMDI()){
  122.       commandsArray = new Array(LABEL_MainMenu, LABEL_SitePanel, SEPARATOR_STR, LABEL_HTMLWindow, LABEL_MainWindow, LABEL_SiteWindow, LABEL_Snippets );
  123.     }else{
  124.       commandsArray = new Array(LABEL_MainMenu, LABEL_SiteMenu, SEPARATOR_STR, LABEL_HTMLWindow, LABEL_MainWindow, LABEL_SiteWindow, LABEL_Snippets );
  125.     }
  126.   }else{
  127.     commandsArray = new Array(LABEL_MainMenu,SEPARATOR_STR, LABEL_HTMLWindow, LABEL_MainWindow, LABEL_Snippets);
  128.   }
  129.   MENU_COMMANDS.setAll(commandsArray,commandsArray);
  130.   MENU_COMMANDS.setIndex(0);
  131.  
  132.   // create treenode array
  133.   for (i=0; i < MENU_COMMANDS.getLen(); i++)
  134.   {
  135.     menuLabel = MENU_COMMANDS.get(i);
  136.     if (menuLabel == LABEL_MainMenu)
  137.     ARRAY_COMMANDS_TREENODES.push(readFromMenuXML("menubar","DWMainWindow", ""));
  138.   else if (menuLabel == LABEL_SiteMenu)
  139.     ARRAY_COMMANDS_TREENODES.push(readFromMenuXML("menubar","DWMainSite", ""));
  140.   else if (menuLabel == LABEL_SitePanel)
  141.     ARRAY_COMMANDS_TREENODES.push(readFromMenuXML("menubar","DWSitePseudoMenu", ""));
  142.   else if (menuLabel == LABEL_HTMLWindow)
  143.     ARRAY_COMMANDS_TREENODES.push(readFromMenuXML("shortcutlist","DWHTMLContext", "Snippets"));
  144.   else if (menuLabel == LABEL_MainWindow)
  145.     ARRAY_COMMANDS_TREENODES.push(readFromMenuXML("shortcutlist","DWMainWindow", ""));
  146.   else if (menuLabel == LABEL_SiteWindow)
  147.     ARRAY_COMMANDS_TREENODES.push(readFromMenuXML("shortcutlist","DWMainSite", ""));
  148.   else if (menuLabel == LABEL_Snippets)
  149.     //ARRAY_COMMANDS_TREENODES.push(readFromMenuXML("shortcutlist","DWMainSite", ""));*/
  150.     ARRAY_COMMANDS_TREENODES.push(readFromSnippetsXML());
  151.   else
  152.     ARRAY_COMMANDS_TREENODES.push( "-");
  153.   }
  154.  
  155.   generateTreeArray();
  156.  
  157.   setCommands();
  158.   // ** compare active and current set
  159.   CURRENT_SHORTCUT_LIST.shortcutListName = ACTIVE_SET_STR;
  160.   setShortcutList();
  161.     MENU_CURRENT_SET.focus();
  162.  
  163. }
  164.  
  165. function adjustButtons()
  166. {
  167.   if (PLATFORM=="Win32")
  168.   {
  169.     document.leftBtn.innerHTML = '<input type="button" name="okBtn" value=' + MM.BTN_OK + ' style="width:75px;height:21px" onClick="cmdOK()">';
  170.     document.middleBtn.innerHTML = '<input type="button" name="cancelBtn" value=' + MM.BTN_Cancel + ' style="width:75px;height:21px" onClick="cmdCancel()">';
  171.     document.rightBtn.innerHTML = '<input type="button" name="helpBtn" value=' + MM.BTN_Help + ' style="width:75px;height:21px" onClick="displayHelp()">';
  172.   }
  173. }
  174.  
  175. // getCustomSetList
  176. // gets the list of custom sets. in DW4, this function returned a single array of
  177. // filenames. it now returns an array containing two items: an array of set names,
  178. // and an array of set filenames. this is so the set names can be localized independent
  179. // of the filenames.
  180. function getCustomSetList(setType)
  181. {
  182.   var fileObj = new File(FILE_CUSTOM_SET);
  183.   var fileArray = new Array();
  184.   var setNames = new Array();
  185.   var filterFunction;
  186.   var setDOM, setName;
  187.   if (setType == "factory")
  188.     filterFunction =  new Function("x", "return (x.isFile()) && ((x.getAttributes() == 'R') || (x.getContents().indexOf('factory') != -1)) && (x.getExtension()== 'xml');");
  189.   else
  190.     filterFunction =  new Function("x", "return (x.isFile()) && ((x.getAttributes() != 'R') && (x.getContents().indexOf('factory') == -1)) && (x.getExtension()== 'xml');");
  191.   fileArray = fileObj.listFolder(filterFunction);
  192.   
  193.   for (var i=0; i < fileArray.length; i++){
  194.     setDOM = dw.getDocumentDOM(FILE_CUSTOM_SET + "/" + fileArray[i]);
  195.     setName = setDOM.getElementsByTagName('SHORTCUTSET')[0].getAttribute('name');
  196.     setNames.push(setName);
  197.   }
  198.   return new Array(setNames,fileArray);
  199. }
  200.  
  201. // function that walks through the files in the snippets folder to get tree
  202. function readFromSnippetsXML()
  203. {
  204.   var snippetsFile;
  205.   var snippetsList;
  206.   var tempArray = new Array;
  207.  
  208.   snippetsList = MENU_DOM.getElementsByTagName("snippets");
  209.   
  210.   // Call into the C++ layer to read the index.xml file into our desired html 
  211.   // This call traverses the snippet tags in the snippets node and creates treenodes
  212.   // Returns an object with nodes, and parallel arrays of nodenames and keys
  213.   
  214.   //******************TODO*********************//
  215.   // var treeData = null;//dw.getSnippetsTree(FOLDER_SNIPPETS_PATH);
  216.   var treeData = dw.getSnippetsTree(FILE_MENUXML_PATH);
  217.   
  218.   // It's possible in theory, although highly unlikely, to get NULL back from getMenuTree(),
  219.   // so fail gracefully and return an empty list, and bypass adding stuff to the shortcut list
  220.  
  221.   if(treeData == null)
  222.     return (new Array());
  223.     
  224.   var nodes = treeData.nodes;
  225.   
  226.   // Use the nodename and keys stuff from the C++ call to populate our shortcutlists too
  227.   addShortcutsFromTree(treeData);
  228.  
  229.   return nodes;  
  230. }
  231.  
  232. // function reads in menus.xml and creates the treecontrol
  233. function readFromMenuXML(tagName,id, ignoreId)
  234. {
  235.   loadGlobals();
  236.  
  237.   var menuFile, theMenubar, i, menubarList;
  238.   var tempArray = new Array();
  239.  
  240.   menuFile = new File(FILE_MENUXML_PATH);
  241.   if (!menuFile.exists)
  242.   {
  243.     menuFile.setPath(FILE_CONFIG_PATH + '/Menus/menus.bak');
  244.     menuFile.copyTo(FILE_MENUXML_PATH);
  245.   }
  246.   menuFile.setPath(FILE_MENUXML_PATH);
  247.   menubarList = MENU_DOM.getElementsByTagName(tagName);
  248.   theMenubar = getMenuTagByID(menubarList,id);
  249.  
  250.   // Call into the C++ layer to read the menus.xml file into our desired html 
  251.    // This call traverses the menus in the menubar node and creates treenodes
  252.    // Returns an object with nodes, and parallel arrays of nodenames and keys
  253.   // Since snippets are now included in the shortcut list, and should be 
  254.   // displayed under it's own category, ignore all snippet tags found under
  255.   // the shortcutlist.
  256.   var treeData = dw.getMenuTree(FILE_MENUXML_PATH, tagName, id, ignoreId);
  257.   
  258.   // It's possible in theory, although highly unlikely, to get NULL back from getMenuTree(),
  259.   // so fail gracefully and return an empty list, and bypass adding stuff to the shortcut list
  260.   if(treeData == null)
  261.     return (new Array());
  262.  
  263.   var nodes = treeData.nodes;
  264.  
  265.   // Use the nodename and keys stuff from the C++ call to populate our shortcutlists too
  266.   addShortcutsFromTree(treeData);
  267.  
  268.   return nodes;
  269. }
  270.  
  271.  
  272.  
  273. // function returns the NodeList for the specified tag (it assumes that menus.xml exists).
  274. // Returns null if the tag does not exists.
  275. function getMenuTagByID(menubarList,id)
  276. {
  277.   var   i;
  278.   var found = false;
  279.   for(i=0;i<menubarList.length; i++)
  280.   {
  281.     if  ((menubarList[i].nodeType==Node.ELEMENT_NODE) && (menubarList[i].getAttribute("id") == id))
  282.     {
  283.       found = true;
  284.       break;
  285.     }
  286.   }
  287.   return (found)?menubarList[i]:null;
  288. }
  289.  
  290. // changes the treecontrol when user has selected a different Commands set
  291. function setCommands()
  292. {
  293.   findObject("theTreeControl").innerHTML = ARRAY_COMMANDS_TREE[MENU_COMMANDS.getIndex()];
  294. }
  295.  
  296. // changes the itemList to show the shortcuts for the select tree node
  297. function setShortcutList()
  298. {
  299.   var keyStr="", index, theValue, theSelectedNode;
  300.   theSelectedNode = findObject("theTreeControl").selectedNodes[0];
  301.   if (theSelectedNode)
  302.   {
  303.     theValue = theSelectedNode.value;
  304.     index = theValue.lastIndexOf("|");
  305.     if (index != -1)
  306.       keyStr = theValue.substring(index+1);
  307.   }
  308.   if (keyStr)
  309.     LIST_SHORTCUTS.setAll(keyStr.split(","));
  310.   else
  311.     LIST_SHORTCUTS.setAll(new Array());
  312.   LIST_SHORTCUTS.setIndex(0);
  313. }
  314.  
  315. // updates the key column of the selected treenode
  316. function setShortcutInTree(selectedNode,oldKey,newKey, conflictID)
  317. {
  318.   var  index, treeNodeValue,numUpdates,keyStr;
  319. //  keyStr = LIST_SHORTCUTS.list.toString();
  320.   if (selectedNode)
  321.   {
  322.     numUpdates=CURRENT_SHORTCUT_LIST.update(selectedNode.name, convertKeyStr(newKey,"store"),convertKeyStr(oldKey,"store"));
  323.     keyStr = convertKeyStr(CURRENT_SHORTCUT_LIST.getKeyByID(selectedNode.name),"display")
  324.     treeNodeValue = selectedNode.value;
  325.     if (treeNodeValue.search(/\|/)!=-1){
  326.       treeNodeValue = treeNodeValue.replace(/\|.*/,"|"+keyStr);
  327.     }else
  328.       treeNodeValue += "|"+keyStr;
  329.     selectedNode.setAttribute("value",treeNodeValue);
  330.   }
  331.   else
  332.   {
  333.     numUpdates=1+CURRENT_SHORTCUT_LIST.update(conflictID, convertKeyStr(newKey,"store"),convertKeyStr(oldKey,"store"));
  334.   }
  335.  
  336.   if (numUpdates > 1)
  337.   {
  338.     ARRAY_COMMANDS_TREENODES = updateTreeNodeArray(ARRAY_COMMANDS_TREENODES);
  339.   generateTreeArray();
  340. //  setCommands();
  341.   dw.forceGarbageCollection();
  342.   }
  343.   else
  344.     ARRAY_COMMANDS_TREE[MENU_COMMANDS.getIndex()] = findObject("theTreeControl").innerHTML;
  345. //  document.newShortcutEntry.setAttribute("value", "");
  346.   // *** it would be nice to set A_C_T before user changes commands set instead
  347.  
  348. }
  349.  
  350. function writeToMenusXML(theShortcutList)
  351. {
  352.   loadGlobals();
  353.  
  354.   var i, keyStr, keyArray=new Array(), theId, menuBarNode, menuNode, altId, tempNode, shortcutNode;
  355.   var menuitemList, shortcutItemList, shortcutTagList, menuFile, snippetShortcutTagList;
  356.  
  357.   menuitemList = MENU_DOM.getElementsByTagName("menuItem");
  358.   shortcutItemList = MENU_DOM.getElementsByTagName("shortcut");
  359.   shortcutTagList = MENU_DOM.getElementsByTagName("shortcutlist");
  360.   snippetShortcutTagList = MENU_DOM.getElementsByTagName("snippets");   //TODO: make sure this is the right tag name - there should only be one of these
  361.  
  362.   for (i=0;i<theShortcutList.idKeyPairList.length; i++ )
  363.   {
  364.     keyArray = theShortcutList.idKeyPairList[i].keysArray;
  365.  
  366.     theId = theShortcutList.idKeyPairList[i].id;
  367.  
  368.     var bIsSnippet = false;
  369.     
  370.     if (theId && theShortcutList.changeList[theId])
  371.     {
  372.       //set the primary key
  373.  
  374.       //first check to see if this is a snippet shortcut
  375.      if (theId.indexOf("Snippets*") == 0){  
  376.          bIsSnippet = true;
  377.          shortcutNode = getMenuTagByID(shortcutItemList, theId);
  378.          if (shortcutNode){
  379.  
  380.             if (keyArray[0])
  381.                 shortcutNode.setAttribute("key", keyArray[0]);
  382.             else
  383.                 shortcutNode.setAttribute("key", "");
  384.          }
  385.          else {  //the shortcut tag does not exist in menus.xml so we need to add it
  386.             tempNode = getMenuTagByID(snippetShortcutTagList, "DWSnippetsContext");  //TODO: need to verify that this is the right ID
  387.             if (tempNode){
  388.                 var keyStr = (keyArray[0]!=null) ? keyArray[0] : "";
  389.                 tempNode.innerHTML += createSnippetShortcutTag(theId, keyStr);
  390.             }
  391.          }
  392.       }
  393.       else {
  394.         if (theId.indexOf("DWShortcut") == -1){
  395.             menuNode = getMenuTagByID(menuitemList, theId);
  396.             if (!menuNode) 
  397.                 menuNode = getMenuTagByID(shortcutItemList, theId);
  398.         }
  399.         else{
  400.             menuNode = getMenuTagByID(shortcutItemList, theId);
  401.             if (!menuNode) 
  402.                 menuNode = getMenuTagByID(menuitemList, theId);
  403.         }
  404.         if (menuNode != null && menuNode.getAttribute("key")!= keyArray[0]){
  405.             if (keyArray[0])
  406.                 menuNode.setAttribute("key", keyArray[0]);
  407.             else
  408.                 menuNode.setAttribute("key", "");
  409.         }
  410.     }
  411.     //set Alternate key
  412.     if (!bIsSnippet)
  413.     {
  414.         shortcutTagID = getTagIdFromItemId(theId,menuNode);
  415.         if (shortcutTagID == "DWMainWindow1")
  416.         {
  417.             rightId = theId.replace(/DWMenu_/,"");
  418.             altId = "DWShortcuts_" + rightId;
  419.             shortcutTagID = shortcutTagID.substr(0,shortcutTagID.length-1);
  420.         }
  421.         else if (shortcutTagID == "DWMainSite1")
  422.         {
  423.             rightId = theId.replace(/DWMenu_MainSite/,"");
  424.             altId = "DWShortcuts_MainSite" + rightId;
  425.             shortcutTagID = shortcutTagID.substr(0,shortcutTagID.length-1);
  426.         }
  427.         else
  428.         {
  429.             altId = theId+"2";
  430.         }
  431.         if (keyArray.length > 1 && menuNode)
  432.         {
  433.             if (getMenuTagByID(shortcutItemList, altId) == null)   // check to see if alt already exists
  434.             {
  435.                 tempNode = getMenuTagByID(shortcutTagList, shortcutTagID)
  436.                 if (tempNode)
  437.                     tempNode.innerHTML += createAltShortcutTag(menuNode, altId, keyArray[1]);
  438.             }
  439.             else
  440.             {
  441.                 menuNode = getMenuTagByID(shortcutItemList, altId);
  442.                 if (menuNode)
  443.                     menuNode.setAttribute("key", keyArray[1]);
  444.                 if (menuNode.getAttribute("platform")==OPP_PLATFORM)
  445.                     menuNode.setAttribute("platform", "");
  446.             }
  447.         }
  448.         else if ((menuNode = getMenuTagByID(shortcutItemList, altId)) != null)
  449.         {
  450.             if (menuNode.getAttribute("platform")!=OPP_PLATFORM)
  451.             menuNode.setAttribute("key", "");
  452.         }
  453.             }    
  454.     }
  455.   }
  456.   menuFile = new File(FILE_MENUXML_PATH);
  457.  
  458.   if (dreamweaver.appVersion && (dreamweaver.appVersion.indexOf('ja') != -1 || 
  459.                                  dreamweaver.appVersion.indexOf('ko') != -1 ||
  460.                                  dreamweaver.appVersion.indexOf('zh') != -1) )
  461.     menuFile.setContents(MENU_DOM.body.outerHTML);
  462.   else
  463.     menuFile.setContents(dreamweaver.nativeToLatin1(MENU_DOM.body.outerHTML));
  464. }
  465.  
  466. function createAltShortcutTag(origNode, newId, newKey)
  467. {
  468.  
  469.   var retVal = new Array(), value;
  470.   var attrArray  = new Array("file","command","domRequired","arguments","enabled","name")
  471.   retVal.push(NEWLINE + "    <shortcut key=" + '"' + newKey + '"');
  472.   for (var i=0; i<attrArray.length; i++)
  473.   {
  474.     if ((value = origNode.getAttribute(attrArray[i])))
  475.       retVal.push("   "+attrArray[i]+"=" + '"' + value + '"');
  476.   }
  477.   retVal.push("   id=" + '"' + newId + '" />'+NEWLINE);
  478.   return retVal.join("");
  479. }
  480.  
  481. function createSnippetShortcutTag( newId, newKey)
  482. {
  483.     //remember to replace \ with / in path code insertSnippet command
  484.   var retVal = new Array();
  485.   var relPath;
  486.   relPath = convertSnippetIDtoRelPath(newId)
  487.   retVal.push(NEWLINE + "        <SHORTCUT key=" + '"' + newKey + '"');
  488.   retVal.push ("  " + "domRequired=" +'"' + 'FALSE' + '"');
  489.   retVal.push ("  " + "command=\"dw.snippetPalette.insertSnippet(" + "'" + relPath + "')\"" );
  490.   retVal.push("   id=" + '"' + newId + '" />'+NEWLINE);
  491.   return retVal.join("");
  492. }
  493.  
  494. function convertSnippetIDtoRelPath(theID)
  495. {
  496.     // convert an ID that looks like... Snippets*Custom*rubberducky.csn to Snippets\\Custom\\rubberducky.csn
  497.     var relPath;
  498.     var snippetPrefix = "Snippets*"
  499.     theID = theID.substring(snippetPrefix.length);
  500.     relPath = theID.replace(/\*/g,"\\\\" );
  501.     return relPath;
  502. }
  503.  
  504. // Given an items it, returns the id of the menubar id
  505. function getTagIdFromItemId(itemId,menuNode)
  506. {
  507.   var retVal="",parent, parentId;
  508.   parent = menuNode.parentNode;
  509.   if (menuNode)
  510.   {
  511.     if (parent.tagName =="SHORTCUTLIST")
  512.       retVal = parent.getAttribute("id");
  513.     else
  514.     {
  515.       while (parent && !parentId)
  516.       {
  517.         if (parent.tagName =="MENUBAR")
  518.           parentId = parent.getAttribute("id");
  519.         else
  520.           parent = parent.parentNode;
  521.       }
  522.     }
  523.     if (parentId)
  524.     {
  525.       if (parentId =="DWMainSite")
  526.         retVal = "DWMainSite1"
  527.       else if (parentId =="DWMainWindow")
  528.         retVal = "DWMainWindow1"
  529.     }
  530.   }
  531.   return retVal;
  532. }
  533.  
  534. function getAltKeyId(id)
  535. {
  536.  var retVal="";
  537.  if (!id )
  538.    return retVal;
  539.  else if (id.indexOf("DWMenu_")!=-1)
  540.    retVal = id.replace(/DWMenu_/,"DWShortcuts_");
  541.  else if (id)
  542.    retVal = id+"2";
  543.  return retVal;
  544. }
  545.  
  546. function isShortcutToExclude(id)
  547. {
  548.   var retVal=true,i, tempId;
  549.   var idPrefixArray = new Array("DWShortcuts_Main_","DWShortcuts_Site_","DWShortcuts_HTMLSource_");
  550.   if (id && id.indexOf("DWShortcuts")!=-1)
  551.   {
  552.   var tempId = (id.charAt(id.length-1)=="2") ? id.substring(0,id.length-1): "";
  553.   if (tempId && CURRENT_SHORTCUT_LIST.getIndexByID(tempId) != -1)
  554.     retVal = true;
  555.   else
  556.   {
  557.       for (i=0;i<idPrefixArray.length;i++)
  558.       {
  559.         if (id && id.indexOf(idPrefixArray[i]) != -1)
  560.         {
  561.           retVal = false;
  562.           break;
  563.         }
  564.       }
  565.     }
  566.   }
  567.   else retVal=false;
  568.   return retVal;
  569. }
  570.  
  571. function getIndexOfItem(theArray,theItem)
  572. {
  573.   var index,found=false;
  574.   for (index=0;index<theArray.length;index++)
  575.   {
  576.     if (theArray[index] == theItem)
  577.     {
  578.       found=true;
  579.       break;
  580.     }
  581.   }
  582.   return (found)? index:-1;
  583. }
  584.  
  585. function updateUI(itemName)
  586. {
  587.   var newSetFile, newSetName, retVal, tempStr,errorMsg,selectedTreeNode,keyStr,oldKey,numUpdate,otherNode;
  588.   var tempShortcutList;
  589.   switch(itemName)
  590.   {
  591.     case "selectCurrentSet":
  592.   {
  593.     if (MENU_CURRENT_SET.get() == SEPARATOR_STR)
  594.     {
  595.         MENU_CURRENT_SET.pickValue(LAST_VALID_COMMAND_MI);
  596.         //document.commandsList.focus()
  597.     }
  598.     else
  599.     {
  600.       if  (!isSet(MENU_CURRENT_SET.getValue(), "factory")
  601.            && (CURRENT_SHORTCUT_LIST.changeListLength() > 0 )&& confirm(MSG_SaveShortcutSet))
  602.       CURRENT_SHORTCUT_LIST.writeToShortcutXML(FILE_CUSTOM_SET+"/" + MENU_CURRENT_SET.getValue(), CURRENT_SHORTCUT_LIST.shortcutListName);
  603.       MM.setBusyCursor();
  604.       newSetFile = MENU_CURRENT_SET.getValue();
  605.       if (getExtension(newSetFile) !="xml")
  606.         newSetFile+=".xml"
  607.       tempShortcutList = new ShortcutList();
  608.       tempShortcutList.readFromShortcutXML(FILE_CUSTOM_SET+"/" + newSetFile);
  609.       CURRENT_SHORTCUT_LIST.compareUpdate(tempShortcutList);
  610.       ARRAY_COMMANDS_TREENODES = updateTreeNodeArray(ARRAY_COMMANDS_TREENODES);
  611.       generateTreeArray();
  612.       setCommands();
  613.       dw.forceGarbageCollection();
  614.       MM.clearBusyCursor();
  615.     }
  616.     LIST_SHORTCUTS.setAll("");
  617.     clearField("newShortcutEntry");
  618.     LAST_VALID_COMMAND_MI = MENU_CURRENT_SET.getValue();
  619.     MENU_CURRENT_SET.focus()
  620.     break;
  621.   }
  622.   case "duplicateBtn":
  623.     {
  624.     newSetName = callCommand("duplicate set",new Array(MENU_CURRENT_SET.getValue(),CURRENT_SHORTCUT_LIST));
  625.     if (newSetName)
  626.     {
  627.       CURRENT_SHORTCUT_LIST.shortcutListName = newSetName;
  628.       DWfile.write(FILE_ACTIVE_SET,newSetName);
  629.       setCurrentSetMenu();
  630.       MENU_CURRENT_SET.setIndex(getIndexOfItem(MENU_CURRENT_SET.get('all'),newSetName));
  631.       updateUI("selectCurrentSet");
  632.     }
  633.     break;
  634.     }
  635.   case "renameBtn":
  636.   {
  637.     if (!isSet(MENU_CURRENT_SET.getValue(), "factory"))
  638.     {
  639.       newSetName = callCommand("rename set",MENU_CURRENT_SET.getValue());
  640.       if (newSetName)
  641.       {
  642.         CURRENT_SHORTCUT_LIST.shortcutListName = newSetName;
  643.         DWfile.write(FILE_ACTIVE_SET,newSetName);
  644.         setCurrentSetMenu();
  645.         MENU_CURRENT_SET.setIndex(getIndexOfItem(MENU_CURRENT_SET.get('all'),newSetName));
  646.       }
  647.     }
  648.     else
  649.       alert(MSG_CannotRenameFactorySet);
  650.     break;
  651.   }
  652.   case "deleteBtn":
  653.   {
  654.     tempStr = CURRENT_SHORTCUT_LIST.shortcutListName;
  655.     tempStr = tempStr.replace(/.xml/,"");
  656.     retVal = callCommand("delete set",tempStr);
  657.     if (retVal)
  658.     {
  659.       setCurrentSetMenu();
  660.       MENU_CURRENT_SET.setIndex(getIndexOfItem(MENU_CURRENT_SET.get('all'),ACTIVE_SET_STR));
  661.     }
  662.     break;
  663.   }
  664.   case "commandsList":
  665.   { // update the treecontrol
  666.     if (MENU_COMMANDS.get() ==SEPARATOR_STR)
  667.     {
  668.       MENU_COMMANDS.setIndex(MENU_COMMANDS.getIndex()-1);
  669.       updateUI("commandsList");
  670.     }
  671.     else
  672.       setCommands();
  673.     document.newShortcutEntry.setAttribute("value", "")
  674.     updateUI("newShortcutEntry");
  675.     LIST_SHORTCUTS.setAll("");
  676.     break;
  677.   }
  678.   case "theTreeControl":
  679.   {
  680.     ARRAY_COMMANDS_TREE[MENU_COMMANDS.getIndex()] = findObject("theTreeControl").innerHTML;
  681.     setShortcutList();
  682.     clearField("newShortcutEntry");
  683.     break;
  684.   }
  685.   case "addBtn":
  686.   { // node.childNodes.length
  687.     if (!isSet(MENU_CURRENT_SET.getValue(), "factory"))
  688.     {
  689.         selectedTreeNode = findObject("theTreeControl").selectedNodes[0];
  690.       if (selectedTreeNode && selectedTreeNode.childNodes.length == 0 )
  691.       {
  692.         if ((LIST_SHORTCUTS.getLen()==0 || LIST_SHORTCUTS.get() !="" ) && LIST_SHORTCUTS.getLen() < 2)
  693.         {
  694.           LIST_SHORTCUTS.append();
  695.           document.newShortcutEntry.focus();
  696.           document.newShortcutEntry.select();
  697.         }
  698.     }
  699.       }
  700.     else
  701.     {
  702.       if (confirm (MSG_FactorySetCannotBeModified))
  703.         updateUI("duplicateBtn");
  704.     }
  705.     break;
  706.   }
  707.   case "minusBtn":
  708.   {
  709.     if (findObject("theTreeControl").selectedNodes[0])
  710.     {
  711.       if (!isSet(MENU_CURRENT_SET.getValue(), "factory"))
  712.       {
  713.         if (LIST_SHORTCUTS.getLen!=0)
  714.         {
  715.           selectedTreeNode = findObject("theTreeControl").selectedNodes[0];
  716.           oldKey = LIST_SHORTCUTS.get();
  717.           
  718.           if (oldKey)
  719.             setShortcutInTree(selectedTreeNode,oldKey,"");
  720.           
  721.           LIST_SHORTCUTS.del();
  722.           SNIPPETS_MODIFIED = true;
  723.         }
  724.       }
  725.       else
  726.       {
  727.         if (confirm (MSG_FactorySetCannotBeModified))
  728.           updateUI("duplicateBtn");
  729.       }
  730.     }
  731.     break;
  732.   }
  733.   case "newShortcutEntry":
  734.   {
  735.     if (!document.newShortcutEntry.value || !isSet(MENU_CURRENT_SET.getValue(), "factory"))
  736.     {
  737.       errorMsg = checkKeyForConflict(convertKeyStr(document.newShortcutEntry.value,"store"));
  738.       if(errorMsg)
  739.       {
  740.         findObject("warningMessage").innerHTML = errorMsg;
  741.       }
  742.       else if(findObject("warningMessage").innerHTML != "")
  743.       {
  744.           findObject("warningMessage").innerHTML = "";
  745.       }
  746.       }
  747.       else
  748.       {
  749.       if (confirm (MSG_FactorySetCannotBeModified))
  750.         updateUI("duplicateBtn");
  751.     }
  752. //    if (document.newShortcutEntry.value=="")
  753. //    {
  754. //        document.applyButton.setAttribute("disabled","true");
  755. //    }
  756.     break;
  757.   }
  758.   case "applyButton":
  759.   {
  760.     if (CAN_APPLY)
  761.     {
  762.       if (!isSet(MENU_CURRENT_SET.getValue(), "factory"))
  763.       {
  764.         selectedTreeNode = findObject("theTreeControl").selectedNodes[0];
  765.         if (!selectedTreeNode || selectedTreeNode.childNodes.length != 0 )
  766.           break;
  767.         if (CONFLICT_ID && !confirm(errMsg(MSG_ReassignShortcut,getNameFromTreeArray(CONFLICT_ID),getNameFromTreeArray(document.theTreeControl.selectedNodes[0].name))))
  768.           break;
  769.         else
  770.         {
  771.           if (CONFLICT_ID)
  772.           {
  773. //            CURRENT_SHORTCUT_LIST.update(CONFLICT_ID,"",convertKeyStr(document.newShortcutEntry.value,"store"));
  774.             otherNode = document.theTreeControl[CONFLICT_ID];
  775.             if (otherNode)
  776.               setShortcutInTree(otherNode,document.newShortcutEntry.value,"")
  777.             else
  778.               setShortcutInTree(null,document.newShortcutEntry.value,"",CONFLICT_ID);
  779.           }
  780.           if (LIST_SHORTCUTS.getLen() == 0)
  781.             LIST_SHORTCUTS.add("");
  782.           oldKey = LIST_SHORTCUTS.get();
  783.           LIST_SHORTCUTS.set(document.newShortcutEntry.value);
  784.           setShortcutInTree(selectedTreeNode,oldKey,document.newShortcutEntry.value);
  785.         }
  786.       }
  787.       else
  788.       {
  789.         if (confirm (MSG_FactorySetCannotBeModified))
  790.           updateUI("duplicateBtn");
  791.       }
  792.       document.newShortcutEntry.setAttribute("value", "")
  793.       updateUI("newShortcutEntry");
  794.       SNIPPETS_MODIFIED = true;
  795.     }
  796.     dw.forceGarbageCollection();
  797.     break;
  798.   }
  799.   }
  800. }
  801.  
  802. function generateTreeControlHtml(treeNodesArray)
  803. {
  804.   var retVal = new Array();
  805.   var treeControlTag = 'MM:TREECONTROL';
  806.   var treeColumnTag = 'MM:TREECOLUMN';
  807.   var treeColWidth = (PLATFORM=="Win32") ? TREE_COLUMN_ITEM_WIDTH : TREE_COLUMN_ITEM_WIDTH_MAC;
  808.   retVal.push( "  <" + treeColumnTag + ' name="menuitems" ' + TREE_COLUMN_ITEM_WIDTH + '>' + NEWLINE);
  809.   retVal.push("  <" + treeColumnTag + ' name="shortcutKeys" ' + TREE_COLUMN_KEY_WIDTH + '>' + NEWLINE);
  810.   if (treeNodesArray)
  811.      retVal.push(treeNodesArray.join(""));
  812.   return retVal.join("");
  813. }
  814.  
  815. function generateTreeArray()
  816. {
  817.   var i=0;
  818.   if (ARRAY_COMMANDS_TREE.length==0)
  819.     ARRAY_COMMANDS_TREE.length = ARRAY_COMMANDS_TREENODES.length;
  820.   for (i=0;i<ARRAY_COMMANDS_TREENODES.length;i++)
  821.   {
  822.     if (ARRAY_COMMANDS_TREENODES[i] !="-")
  823.       ARRAY_COMMANDS_TREE[i]=generateTreeControlHtml(ARRAY_COMMANDS_TREENODES[i]);
  824.     else
  825.       ARRAY_COMMANDS_TREE[i] = "-";
  826.   }
  827. }
  828.  
  829. function updateTreeNodeArray(arrayOfTreeNodeArrays)
  830. {
  831.   var i, x, theNodeStr;
  832.   for (i=0; i < arrayOfTreeNodeArrays.length; i++)
  833.   {
  834.     for (x=0; x <  arrayOfTreeNodeArrays[i].length; x++)
  835.     {
  836.       theNodeStr = updateTreeNode(arrayOfTreeNodeArrays[i][x]);
  837.       if (theNodeStr != arrayOfTreeNodeArrays[i][x]);
  838.         arrayOfTreeNodeArrays[i][x] = theNodeStr;
  839.     }
  840.   }
  841.   return arrayOfTreeNodeArrays;
  842. }
  843.  
  844. function updateTreeNode(treeNodeStr)
  845. {
  846.   var startIndex=0, keyStr, newStr, endIndex=0;
  847.   if (treeNodeStr.indexOf('name="DW') !=-1)
  848.   {
  849.     startIndex = treeNodeStr.indexOf('name="DW',startIndex)+6;
  850.     endIndex = treeNodeStr.indexOf('"',startIndex);
  851.     theId = treeNodeStr.substr(startIndex, endIndex-startIndex);
  852.  
  853.     // get keyStr for the given id
  854.     keyStr = convertKeyStr(CURRENT_SHORTCUT_LIST.getKeyByID(theId),"display");
  855.   if(treeNodeStr.indexOf("|"+keyStr+'"') == -1 ||!keyStr && treeNodeStr.indexOf("|")!=-1)
  856.     {
  857.       startIndex=treeNodeStr.indexOf("|");
  858.       if (startIndex==-1)
  859.       {
  860.         startIndex = treeNodeStr.indexOf('value="')+7;
  861.         startIndex = treeNodeStr.indexOf('"',startIndex);
  862.       }
  863.       endIndex = treeNodeStr.indexOf('"', startIndex);
  864.       newStr = treeNodeStr.substr(0, startIndex);
  865.       if (keyStr) newStr += "|";
  866.         newStr += keyStr + treeNodeStr.substr(endIndex);
  867.       treeNodeStr = newStr;
  868.     }
  869.   }
  870.   return treeNodeStr;
  871. }
  872.  
  873. function setCurrentSetMenu()
  874. {
  875.   var factorySets = getCustomSetList("factory");
  876.   var customSets = getCustomSetList("custom");
  877.   if (customSets[0].length !=0){
  878.     factorySets[0].push(SEPARATOR_STR);
  879.     factorySets[1].push(SEPARATOR_STR);
  880.   }
  881.   var currentSetNames = factorySets[0].concat(customSets[0]);
  882.   var currentSetFiles = factorySets[1].concat(customSets[1]);
  883.  
  884.   ACTIVE_SET_STR = DWfile.read(FILE_ACTIVE_SET);
  885.   MENU_CURRENT_SET.setAll(currentSetNames,currentSetFiles);
  886. }
  887.  
  888. function isKeyWithoutCtrl(theKey)
  889. {
  890.   var retVal=false;
  891.   if (theKey.length == 1)
  892.     retVal = true;
  893.   else
  894.   {
  895.     index = theKey.lastIndexOf("+");
  896.     tempStr = theKey.substring(index+1);
  897.     if (PLATFORM=="Win32")
  898.     {
  899.       if (tempStr.length == 1 && theKey.indexOf("Cmd") == -1 && theKey.indexOf("Ctrl") == -1)
  900.         retVal = true;
  901.     }
  902.     else 
  903.     {
  904.       if (tempStr.length == 1 && theKey.indexOf("Cmd") == -1)
  905.         retVal = true;
  906.     }
  907.   }
  908.   return retVal;
  909. }
  910.  
  911. // returns error message if the given shortcut key is invalid
  912. function checkKeyForConflict(newKey)
  913. {
  914.   var retVal, conflictId;
  915.   if (newKey)
  916.     conflictId = CURRENT_SHORTCUT_LIST.getIdByKey(newKey);
  917.   if (PLATFORM == "Win32" && conflictId == "" && newKey.indexOf("Cmd") != -1)
  918.   {
  919.       newKey = newKey.replace(/Cmd/,"Ctrl");
  920.       conflictId = CURRENT_SHORTCUT_LIST.getIdByKey(newKey);
  921.   }
  922.       
  923.   CONFLICT_ID = conflictId;
  924.   if (isKeyWithoutCtrl(newKey))
  925.   {
  926.     retVal = createWarningMsg();
  927.     CAN_APPLY = false;
  928. //    document.applyButton.setAttribute("disabled","true");
  929.   }
  930.   else
  931.   {
  932. //    document.applyButton.removeAttribute("disabled");
  933.     CAN_APPLY = true;
  934.     if (conflictId)
  935.       retVal = createWarningMsg(getNameFromTreeArray(conflictId));
  936.     else
  937.       retVal="";
  938.   }
  939.   return retVal;
  940. }
  941.  
  942. function createWarningMsg(theId)
  943. {
  944.   var retVal = new Array();
  945.   if (theId)
  946.   {
  947.     imagePath = YIELD_PATH;
  948.     messageStr = MSG_ShortcutAssigned;
  949.     errorMsgArg = theId;
  950.   }
  951.   else
  952.   {
  953.     imagePath = STOP_PATH;
  954.     messageStr = MSG_LetterShortcutMustHaveCtrl;
  955.     errorMsgArg = CTRL_STR;
  956.   }
  957.   retVal.push('<img src="'+ imagePath + '" width="12" height="12" >');
  958.   retVal.push(errMsg(messageStr, errorMsgArg));
  959.   return retVal.join("");
  960. }
  961.  
  962.  
  963. function isSet(setFileName, setType)
  964. {
  965.   var facSetArray = new Array(), i, retVal = false;
  966.   facSetArray = getCustomSetList(setType)[1];
  967.   if (setFileName.lastIndexOf(".xml") != setFileName.length-4)
  968.     setFileName = setFileName + ".xml";
  969.   for (i=0; i<facSetArray.length; i++)
  970.   {
  971.     if (facSetArray[i] == setFileName)
  972.     {
  973.       retVal = true;
  974.       break;
  975.     }
  976.   }
  977.   return retVal;
  978. }
  979.  
  980. function createHTMLContents()
  981. {
  982.   var retVal = new Array(), i, treeNodeStr, keyStr,currLevel;
  983.   var nextNodeStr="",isBold,tempNodeStr;
  984.   var closeTreeNodeStr='</MM:TREENODE>'+ NEWLINE;
  985.   retVal.push("<HTML>"+NEWLINE+"<HEAD>");
  986.   retVal.push("<TITLE>" + CURRENT_SHORTCUT_LIST.shortcutListName + " Shortcut Set" + "</TITLE>" +NEWLINE);
  987.   retVal.push('<style type="text/css">\n<!--\nbody {font-family:  '  + cssfontStr + '; text-align: center}\ntable {  font-size: x-small}\n-->\n</style>')
  988.   retVal.push("</HEAD>"+NEWLINE);
  989.   retVal.push('<BODY BGCOLOR="#FFFFFF">');
  990.   retVal.push('<DIV ALIGN="center">');
  991.   retVal.push('<p><b><font size="6">'+ MENU_CURRENT_SET.get()+'</font></b></p>\n<p><b>' + DW_VERSION + '</b></p>')
  992.   ARRAY_COMMANDS_TREENODES = updateTreeNodeArray(ARRAY_COMMANDS_TREENODES);
  993.   for (i=0;i<ARRAY_COMMANDS_TREENODES.length;i++)
  994.   {
  995.     if (ARRAY_COMMANDS_TREENODES[i]!="-")
  996.     {
  997.       retVal.push("<p><b>"+MENU_COMMANDS.get(i)+"</b></p>"+NEWLINE);
  998.       retVal.push('<TABLE border = "1" cellspacing="0" cellpadding="2">'+NEWLINE);
  999.       for(x=0;x<ARRAY_COMMANDS_TREENODES[i].length;x++)
  1000.       {
  1001.         treeNodeStr = ARRAY_COMMANDS_TREENODES[i][x];
  1002.         for (var k=x+1;k<ARRAY_COMMANDS_TREENODES[i].length;k++)
  1003.         {
  1004.         tempNodeStr = ARRAY_COMMANDS_TREENODES[i][k];
  1005.         if (tempNodeStr != closeTreeNodeStr){
  1006.         nextNodeStr = tempNodeStr;
  1007.           break;
  1008.       }
  1009.       }
  1010.         currLevel = getTreeNodeLevel(treeNodeStr);
  1011.         isBold = (nextNodeStr && (getTreeNodeLevel(nextNodeStr) > currLevel))
  1012.         if (treeNodeStr != closeTreeNodeStr)
  1013.       {
  1014.           retVal.push("<TR>"+NEWLINE);
  1015.         retVal.push("<TD>");
  1016.         for(var j=0; j<currLevel*4; j++)
  1017.           retVal.push(" ")
  1018.         if (isBold)
  1019.           retVal.push("<b>");
  1020.         retVal.push(getTreeNodeValue(treeNodeStr,1))
  1021.         if (isBold)
  1022.           retVal.push("</b>");
  1023.         retVal.push("</TD>"+NEWLINE);
  1024.         keyStr = getTreeNodeValue(treeNodeStr,2);
  1025.         if (!keyStr) keyStr = " ";
  1026.         retVal.push("<TD>"+keyStr+"</TD>"+NEWLINE);
  1027.         retVal.push("</TR>"+NEWLINE);
  1028.       }
  1029.       }
  1030.       retVal.push("</TABLE>");
  1031.     }
  1032.   }
  1033.   retVal.push("</div>"+NEWLINE + "</BODY>"+NEWLINE+"</HTML>");
  1034.   return retVal.join("");
  1035. }
  1036.  
  1037. function getTreeNodeValue(treeNodeStr,column)
  1038. {
  1039.   var startIndex, endIndex, valueStr, valueArray, retVal ="";
  1040.   startIndex = treeNodeStr.indexOf('value="')+7;
  1041.   endIndex = treeNodeStr.indexOf('"', startIndex);
  1042.   valueStr = treeNodeStr.substring(startIndex,endIndex);
  1043.   valueArray = valueStr.split("|");
  1044.   if (valueArray.length >= column)
  1045.   retVal = valueArray[column-1];
  1046.   return retVal;
  1047. }
  1048.  
  1049. function getTreeNodeLevel(treeNodeStr)
  1050. {
  1051.   var startIndex, endIndex, valueStr="0", valueArray;
  1052.   startIndex = treeNodeStr.indexOf('level="')+7;
  1053.   endIndex = treeNodeStr.indexOf('"', startIndex);
  1054.   valueStr = treeNodeStr.substring(startIndex,endIndex);
  1055.   return (valueStr) ? valueStr : 0;
  1056. }
  1057.  
  1058. function getSimpleName(filenameArray)
  1059. {
  1060.   var i;
  1061.   for (i=0;i<filenameArray.length;i++)
  1062.   {
  1063.     if (filenameArray[i].lastIndexOf(".xml") == filenameArray[i].length-4)
  1064.       filenameArray[i] = filenameArray[i].replace(/.xml/,"");
  1065.   }
  1066.   return filenameArray;
  1067. }
  1068.  
  1069. function getExtension(fileName)
  1070. {
  1071.   var retVal = "", index;
  1072.  
  1073.   index = fileName.lastIndexOf(".");
  1074.   if (index != -1)
  1075.     retVal = fileName.substring(index+1);
  1076.   return retVal;
  1077. }
  1078.  
  1079. function getSimpleFileName(fileName)
  1080. {
  1081.   var index; retVal = fileName;
  1082.  
  1083.   index = fileName.lastIndexOf(".");
  1084.   if (index != -1)
  1085.     retVal = fileName.substring(0,index);
  1086.   return retVal;
  1087. }
  1088.  
  1089. function convertKeyStr(keyStr,location)
  1090. {
  1091.   var retVal=keyStr;
  1092.   if (PLATFORM=="Win32")
  1093.   {
  1094.     if (location === "display")
  1095.     {
  1096.       if (retVal.indexOf("Cmd")!=-1)
  1097.         retVal = retVal.replace(/Cmd/g,"Ctrl");
  1098.       if (retVal.indexOf("Opt")!=-1)
  1099.         retVal = retVal.replace(/Opt/g,"Alt");
  1100.     }
  1101.     if (location  == "store")
  1102.     {
  1103.       if (retVal.indexOf("Ctrl")!=-1)
  1104.         retVal = retVal.replace(/Ctrl/g,"Cmd");
  1105.       if (retVal.indexOf("Alt")!=-1)
  1106.         retVal = retVal.replace(/Alt/g,"Opt");
  1107.     }
  1108.   }
  1109.   return retVal;
  1110. }
  1111.  
  1112. function getPressedKeys()
  1113. {
  1114.   var eventObj = window.event;
  1115.   var retVal = new Array();
  1116.   var theKeyCode = eventObj.keyCode;
  1117.   var charCode = dw.mapKeyCodeToChar(theKeyCode);
  1118.   var keyStr = KEY_CODES[theKeyCode];
  1119.   var modifierFound = false, nonModifier=false;
  1120.   if (eventObj.ctrlKey)
  1121.     retVal.push("Ctrl");
  1122.   if (eventObj.cmdKey)
  1123.     retVal.push("Cmd");
  1124.   if (eventObj.altKey)
  1125.     retVal.push(ALT_STR);
  1126.   if (eventObj.shiftKey)
  1127.     retVal.push("Shift");
  1128.   if (keyStr)
  1129.   retVal.push(keyStr);
  1130.   else if (charCode !=0)
  1131.     retVal.push(String.fromCharCode(charCode));
  1132.  
  1133.   // allow tab and shift-tab to move cursor in and out off newShortcutEntry
  1134.   if (retVal.length == 1 && keyStr == "Tab"){
  1135.           document.theForm.applyButton.focus();
  1136.           return false;
  1137.   }
  1138.  
  1139.   if (retVal.length == 2 && retVal[0]== 'Shift' && keyStr == "Tab"){
  1140.           document.theForm.itemList.focus();
  1141.           return false;
  1142.   }
  1143.  
  1144.   for (var i=0; i<retVal.length; i++)
  1145.   {
  1146.   modifierFound=false;
  1147.     for (var j=0; j<MODIFIER_KEYS.length; j++)
  1148.     {
  1149.       if (MODIFIER_KEYS[j]== retVal[i])
  1150.       {
  1151.     modifierFound = true;
  1152.       break;
  1153.     }
  1154.   }
  1155.   if (!modifierFound)
  1156.   {
  1157.       nonModifier=true;
  1158.     break;
  1159.     }
  1160.   }
  1161.   if (retVal[0] && nonModifier)
  1162.     document.newShortcutEntry.value = (retVal.length > 1) ? retVal.join("+") : retVal[0];
  1163.   else
  1164.     document.newShortcutEntry.value = "";
  1165.   return false;
  1166. }
  1167.  
  1168. function clearField(objName)
  1169. {
  1170.   document[objName].value = "";
  1171.   updateUI(objName);
  1172. }
  1173.  
  1174. function getNameFromTreeArray(id)
  1175. {
  1176.   var i,x, startIndex, endIndex, pipeIndex, idFound, retVal="";
  1177.  
  1178.   for (i=0; i<ARRAY_COMMANDS_TREENODES.length; i++)
  1179.   {
  1180.     for (x=0; x<ARRAY_COMMANDS_TREENODES[i].length; x++)
  1181.     {
  1182.       nodeStr = ARRAY_COMMANDS_TREENODES[i][x];
  1183.       startIndex = nodeStr.indexOf('name="') + 6;
  1184.       if (startIndex >=6)
  1185.       {
  1186.         endIndex=nodeStr.indexOf('"',startIndex);
  1187.       nodeName=nodeStr.substring(startIndex, endIndex);
  1188.       }
  1189.       if (nodeName == id)
  1190.       {
  1191.         startIndex=nodeStr.indexOf('value="') + 7;
  1192.         if (startIndex >= 7)
  1193.         {
  1194.           pipeIndex = nodeStr.indexOf("|", startIndex);
  1195.           endIndex = (pipeIndex == -1) ? nodeStr.indexOf('"',startIndex) : pipeIndex;
  1196.           retVal = nodeStr.substring(startIndex, endIndex);
  1197.         }
  1198.         idFound=true;
  1199.         break;
  1200.       }
  1201.     }
  1202.     if (idFound)
  1203.       break;
  1204.   }
  1205.   return retVal;
  1206. }
  1207.  
  1208. function checkLockedFiles()
  1209. {
  1210.   loadGlobals();
  1211.  
  1212.   retVal = false;
  1213.   fileArray = new Array(FILE_MENUXML_PATH,FILE_ACTIVE_SET);
  1214.   for (var i=0;i<fileArray.length; i++)
  1215.   {
  1216.     if (DWfile.getAttributes(fileArray[i])=="R")
  1217.     {
  1218.       alert(errMsg(MSG_ReadOnlyFile,fileArray[i]));
  1219.       retVal=true;
  1220.     }
  1221.   }
  1222.   return retVal;
  1223. }
  1224.  
  1225. function addShortcutsFromTree(treeData) {
  1226.     var numElts = treeData.names.length;
  1227.     for(var i=0; i < numElts; i++){
  1228.          CURRENT_SHORTCUT_LIST.addShortcut( treeData.names[i],  treeData.keys[i]);
  1229.     }
  1230.     return;
  1231. }
  1232.  
  1233.